package org.lgh.webchatback.controller;

import org.lgh.webchatback.bo.UserBo;
import org.lgh.webchatback.common.R;
import org.lgh.webchatback.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wei-xhh
 * @date 2022-01-19
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("/registerOrLogin")
    public R registerOrLogin(@RequestParam("username") String username,
                             @RequestParam("password") String password,
                             @RequestParam("cid") String cid) {
        return userService.registerOrLogin(username, password, cid);
    }

    @PostMapping("/setNickname")
    public R setNickname(@RequestParam("id") String id,
                             @RequestParam("nickname") String nickname) {
        return userService.setNickname(id, nickname);
    }

    @PostMapping("/uploadFaceBase64")
    public R uploadFaceBase64(@RequestBody UserBo userBo) throws Exception {
        return userService.uploadFaceBase64(userBo);
    }

    @PostMapping("/searchFriend")
    public R searchFriend(@RequestParam("myUserId") String myUserId,
                          @RequestParam("friendUserName") String friendUserName) {
        return userService.searchFriend(myUserId, friendUserName);
    }

    @PostMapping("/addFriendRequest")
    public R addFriendRequest(@RequestParam("myUserId") String myUserId,
                          @RequestParam("friendUserName") String friendUserName) {
        return userService.addFriendRequest(myUserId, friendUserName);
    }

    @PostMapping("/queryFriendRequest")
    public R queryFriendRequest(@RequestParam("userId") String userId) {
        return userService.queryFriendRequest(userId);
    }

    @PostMapping("/operFriendRequest")
    public R operFriendRequest(@RequestParam("acceptUserId") String acceptUserId,
                               @RequestParam("sendUserId") String sendUserId,
                               @RequestParam("operType") String operType) {
        return userService.operFriendRequest(acceptUserId, sendUserId, operType);
    }

    @PostMapping("/myFriends")
    public R myFriends(@RequestParam("userId") String userId) {
        return userService.myFriends(userId);
    }

    @PostMapping("/getUnReadMsgList")
    public R getUnReadMsgList(@RequestParam("acceptUserId") String acceptUserId) {
        return userService.getUnReadMsgList(acceptUserId);
    }

}
